package com.emm.yixun.estate.service.impl.app.manage;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.emm.yixun.basic.service.ProjectPremisesService;
import com.emm.yixun.common.app.GetPremisesListReqDto;
import com.emm.yixun.common.app.GetPremisesListResDto;
import com.emm.yixun.common.app.servletentity.PremisesListRes;
import com.emm.yixun.common.enums.ResultEnum;
import com.emm.yixun.common.model.ProjectPremises;
import com.emm.yixun.common.model.dto.ProjectPremisesDto;

@Service("getPremisesListManage")
public class GetPremisesListManage {

	@Autowired
	private ProjectPremisesService projectPremisesService;
	
	/**
	 * 查询可关注组团(楼盘)
	 * @param reqDto
	 * @return
	 */
	public GetPremisesListResDto getPremisesList(GetPremisesListReqDto reqDto) {
		GetPremisesListResDto resDto = new GetPremisesListResDto();
		try{
			ProjectPremisesDto ppDto = new ProjectPremisesDto();
			ppDto.setMerchantId(reqDto.getMerchantId());
			ppDto.setProjectCode(reqDto.getProjectCode());
			List<ProjectPremises> ppList = projectPremisesService.selectListByDto(ppDto);
			List<PremisesListRes> premisesList = new ArrayList<PremisesListRes>();
			if(ppList.size() > 0){
				for(ProjectPremises pp: ppList){
					PremisesListRes plRes = new PremisesListRes();
					plRes.setPremisesId(String.valueOf(pp.getId()));
					plRes.setPremisesName(pp.getGroupName());
					premisesList.add(plRes);
				}
				resDto.setPremisesList(premisesList);
			}else{
				resDto.setPremisesList(null);
			}
			resDto.setResult(ResultEnum.SUCCESS.getNo());
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("00000");
			resDto.setErrorMsg("可关注组团查询失败!");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		return resDto;
	}
	
}
